home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / procssng / fbm.lzh / FBM / fbm10.zoo / fbedge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-25  |  3.3 KB  |  111 lines

  1. /*****************************************************************
  2.  * fbedge.c: FBM Release 1.0 25-Feb-90 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989,1990 by Gary Sherwin & Michael Mauldin.
  5.  * Permission is granted to use this file in whole or in part for
  6.  * any purpose, educational, recreational or commercial, provided
  7.  * that this copyright notice is retained unchanged.  This software
  8.  * is available to all free of charge by anonymous FTP and in the
  9.  * UUNET archives.
  10.  *
  11.  *
  12.  * fbedge.c: Take derivative and edge detect image
  13.  *
  14.  * USAGE
  15.  *      % fbedge [ flag ] < image > image2
  16.  *
  17.  * EDITLOG
  18.  *      LastEditDate = Mon Jun 25 00:55:55 1990 - Michael Mauldin
  19.  *      LastFileName = /usr2/mlm/src/misc/fbm/fbedge.c
  20.  *
  21.  * HISTORY
  22.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  23.  *    Package for Release 1.0
  24.  *
  25.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  26.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  27.  *
  28.  * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  29.  *    Changed to fbedge.
  30.  *
  31.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  32.  *    Created.
  33.  *****************************************************************/
  34.  
  35. # include <stdio.h>
  36. # include <math.h>
  37. # include "fbm.h"
  38.  
  39. # define USAGE "Usage: fbedge [ -t<threshhold> ] < bitmap > bitmap"
  40.  
  41. #ifndef lint
  42. static char *fbmid =
  43. "$FBM fbedge.c <1.0> 25-Jun-90  (C) 1989,1990 by Gary Sherwin & \
  44. Michael Mauldin, source code available free from MLM@CS.CMU.EDU \
  45. and from UUNET archives$";
  46. #endif
  47.  
  48. main (argc, argv)
  49. char *argv[];
  50. { int w, h, k;
  51.   int blacktrp = 0;
  52.   int outtype = DEF_1BIT;
  53.   FBM input, output;
  54.  
  55.   /* Get the options */
  56.   while (--argc > 0 && (*++argv)[0] == '-')
  57.   { while (*++(*argv))
  58.     { switch (**argv)
  59.       { case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  60.     case 'A':    outtype = FMT_ATK; break;
  61.     case 'B':    outtype = FMT_FACE; break;
  62.     case 'F':    outtype = FMT_FBM; break;
  63.     case 'G':    outtype = FMT_GIF; break;
  64.     case 'I':    outtype = FMT_IFF; break;
  65.     case 'L':    outtype = FMT_LEAF; break;
  66.     case 'M':    outtype = FMT_MCP; break;
  67.     case 'P':    outtype = FMT_PBM; break;
  68.     case 'R':    outtype = FMT_RLE; break;
  69.     case 'S':    outtype = FMT_SUN; break;
  70.     case 'T':    outtype = FMT_TIFF; break;
  71.     case 'X':    outtype = FMT_X11; break;
  72.     case 'Z':    outtype = FMT_PCX; break;
  73.         default:        fprintf (stderr, "%s\n", USAGE);
  74.                         exit (1);
  75.       }
  76.     }
  77.   }
  78.   
  79.   /* Clear the memory pointers so alloc_fbm won't be confused */
  80.   input.cm  = input.bm  = (unsigned char *) NULL;
  81.   output.cm = output.bm = (unsigned char *) NULL;
  82.  
  83.   /* Read the image and clean it */
  84.   if (read_bitmap (&input, (char *) NULL))
  85.   {
  86.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  87.     { fprintf (stderr,
  88.            "Can't handle images with %d bits and %d physbits per pixel\n",
  89.            input.hdr.bits, input.hdr.physbits);
  90.       exit (1);
  91.     }
  92.  
  93.     /* Determine output height & width (oh*ow <= size) */
  94.     h = input.hdr.rows;
  95.     w = input.hdr.cols;
  96.     k = input.hdr.planes;
  97.  
  98.     fprintf (stderr,
  99.          "Edge detect\"%s\", Black-trip %2d [%dx%dx%d]\n",
  100.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  101.          blacktrp, w, h, k);
  102.  
  103.     /* Edge detect the image using a digitial Laplacian */
  104.     if (findedge_fbm (&input, &output, blacktrp) &&
  105.         write_bitmap (&output, stdout, outtype))
  106.     { exit (0); }
  107.   }
  108.   
  109.   exit (1);
  110. }
  111.